// const uuid = require('uuid/v4')
const md5 = require('md5')
const xml2js = require('xml2js')
const Parser = new xml2js.Parser()

const request = require('request')
const prepay = require('../tools/payTools')

const prepay_url = 'https://api.mch.weixin.qq.com/pay/unifiedorder'

module.exports = async (ctx) => {
  const openid = ctx.request.body.openID
  const orderID = ctx.request.body.orderID
  const total_fee = ctx.request.body.total_fee
  const requestIP = ctx.request.ip.replace(/::ffff:/g, '')

  let data = await prepay(openid, orderID, requestIP, total_fee)
  ctx.body = {
    data
  }
}
